//
//  HsLCPersonInfoEditView.m
//  TestIos
//
//  Created by hs on 2020/11/4.
//  Copyright © 2020 Liyadong. All rights reserved.
//

#import "HsLCPersonInfoEditView.h"
#import "Masonry.h"
#import "UIColor+Extend.h"

#define HsLCPersonInfoEditView_W                (MAIN_SCREEN_WIDTH - 2 * 40)

#define HsLCPersonDesEditView_H          236


#define common_left_margin  16

#define info_tf_H       50

 
#define submit_btn_H       40


@interface HsLCPersonInfoEditView ()

/** contentV */
@property (nonatomic, strong) UIView *contentV;

/** titleLabel */
@property (nonatomic, strong) UILabel *mainLabel;

/** tf */
@property (nonatomic, strong) UITextField *infoTF;

/** btn */
@property (nonatomic, strong) UIButton *submitBtn;

/** btn */
@property (nonatomic, strong) UIButton *closeBtn;

@end


@implementation HsLCPersonInfoEditView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addSubview:self.contentV];
        [self.contentV addSubview:self.mainLabel];
        [self.contentV addSubview:self.closeBtn];
        [self.contentV addSubview:self.infoTF];
        [self.contentV addSubview:self.submitBtn];

        UILabel *lineLabel = [self createLine];
        [self.contentV addSubview:lineLabel];
        
        [self.contentV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_equalTo(0);
        }];
        
        
        [self.mainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(40);
            make.right.mas_equalTo(-40);
            make.height.mas_equalTo(20);
            make.top.mas_equalTo(22);
        }];
        
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(0);
            make.centerY.mas_equalTo(self.mainLabel.mas_centerY);
            make.width.height.mas_equalTo(40);
        }];
        
        [self.infoTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(common_left_margin);
            make.right.mas_equalTo(-common_left_margin);
            make.height.mas_equalTo(info_tf_H);
            make.top.mas_equalTo(self.mainLabel.mas_bottom).mas_offset(40);
        }];
        
        [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.infoTF.mas_left);
            make.right.mas_equalTo(self.infoTF.mas_right);
            make.height.mas_equalTo(0.5);
            make.top.mas_equalTo(self.infoTF.mas_bottom);
        }];
        
        [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.infoTF.mas_left);
            make.right.mas_equalTo(self.infoTF.mas_right);
            make.height.mas_equalTo(submit_btn_H);
            make.bottom.mas_equalTo(-30);
        }];
        
    }
    return self;
}


#pragma mark - lazyload
- (UIView *)contentV {
    if (!_contentV) {
        _contentV = [[UIView alloc] initWithFrame:CGRectZero];
        _contentV.backgroundColor = [UIColor whiteColor];
        _contentV.layer.cornerRadius = 4;
        _contentV.layer.masksToBounds = YES;
    }
    return _contentV;
}

- (UILabel *)mainLabel {
    if (!_mainLabel) {
        _mainLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _mainLabel.text = @"编辑标题";
        _mainLabel.textAlignment = NSTextAlignmentCenter;
        _mainLabel.textColor = [UIColor colorWithHexString:@"#2A2B30"];
        UIFont *font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
        _mainLabel.font = font;
    }
    return _mainLabel;
}

- (UITextField *)infoTF {
    if (!_infoTF) {
        _infoTF = [[UITextField alloc] initWithFrame:CGRectZero];
        _infoTF.placeholder = @"请输入内容";
    }
    return _infoTF;
}
 
- (UIButton *)submitBtn {
    if (!_submitBtn) {
        _submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_submitBtn setTitle:@"确定" forState:UIControlStateNormal];
        _submitBtn.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightRegular];
        [_submitBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_submitBtn addTarget:self action:@selector(handleSure:) forControlEvents:UIControlEventTouchUpInside];
        [_submitBtn setBackgroundColor:[UIColor colorWithHexString:@"#EF4034"]];
        _submitBtn.layer.cornerRadius = 4;
        _submitBtn.layer.masksToBounds = YES;
    }
    return _submitBtn;
}

- (UIButton *)closeBtn {
    if (!_closeBtn) {
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setBackgroundColor:[UIColor redColor]];
        [_closeBtn addTarget:self action:@selector(handlClode:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _closeBtn;
}

- (UILabel *)createLine {
    UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    tempLabel.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    return tempLabel;
}

- (void)handleSure:(id)sender {
    NSString *sureText = self.infoTF.text;
    if (self.sureClick) {
        self.sureClick(sureText);
    }
}
- (void)handlClode:(id)sender {
    if (self.closeClick) {
        self.closeClick();
    }
}

- (void)updateInfoShowWithText:(NSString *)text {
    self.infoTF.text = text;
}

-(HsLCPersonInfoEditView *)createEditNameView {
    HsLCPersonInfoEditView *tempView = [[HsLCPersonInfoEditView alloc] initWithFrame:CGRectMake(0, 0, HsLCPersonInfoEditView_W, HsLCPersonDesEditView_H)];
    tempView.mainLabel.text = @"编辑昵称";
    UIFont *myfont = [UIFont systemFontOfSize:17 weight:UIFontWeightRegular];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:@"请输入昵称" attributes:@{
        NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#A6A9B5"],
        NSFontAttributeName:myfont
    }];
    tempView.infoTF.attributedPlaceholder = attrString;
        
    return tempView;
}


 

@end
